﻿@using System.Collections.Concurrent
@using HotelManageSystem.Models
@model HotelManageSystem.Models.BiographyDetial
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<link href= "@Url.Content("~/Content/TelerikGrid.css")"rel="stylesheet" type="text/css" />
<style>
    select
    {
        height: 24px;
        width: 90%;
    }
    input
    {
        height: 23px;
        width: 90%;
    }
    textarea
    {
        max-width: 90%;
        max-height: 50px;
        min-width: 90%;
        min-height: 50px;
        resize: none;
    }
</style>
<script type="text/javascript">
    $(document).ready(function () {
        //让日期选择文本框只读
        $(".t-picker-wrap>input").attr("readonly","readonly");
        
        //点击返回按钮要将BiographDetial/Index加载到content当中来
        //然后设置菜单session为Biography/Index
        $("#BiographyIndex").click(function () {
            $.get("Biography/Index", null, function (data) {
                $("#content").html(data);
            });
            $.post("HumanResources/SetSeesion", { u: "Biography/Index" }, function () { });
        });
        
        //填充部门下拉列表框,根据编辑对象选择某个
        $.get("Biography/GetDepartments", null, function (data) {
            $(data).each(function () {
                var d = document.createElement("option");
                d.value = this["ID"];
                d.text = this["Name"];
                d.selected = @Model.DepartmentId  == this["ID"];
                $("#DepartmentId")[0].options.add(d);
            });
        });
        
        //填充职位下拉列表框,根据编辑对象选择某个
        $.get("Biography/GetPosts", null, function (data) {
            $(data).each(function () {
                var d = document.createElement("option");
                d.value = this["ID"];
                d.text = this["Title"];
                d.selected = @Model.PostId == this["ID"];
                $("#PostId")[0].options.add(d);
            });
        });
        
         //载入时是否为正式状态,设置使用天数的课编辑性
        if ($("#EmployeeStatus").val() == "正式状态") {
            $("#ProbationDates").attr("disabled", "disabled");
            $("#ProbationDates").attr("value", 0);
        }
        else {
            $("#ProbationDates").removeAttr("disabled");
        }
        
        //根据员工状态来设置试用天数的可编辑性
        $("#EmployeeStatus").change(function () {
            if ($("#EmployeeStatus").val() == "正式状态") {
                $("#ProbationDates").attr("disabled", "disabled");
                $("#ProbationDates").attr("value", 0);
            }
            else {
                $("#ProbationDates").removeAttr("disabled");
                $("#ProbationDates").attr("value", 30);
            }
        });
        
    });
</script>
@{ 
    //学历的枚举生成SelectListItem,用于下拉列表框
    var degreeSelectItemList = new List<SelectListItem>();
    degreeSelectItemList.AddRange(
        Enum.GetValues(typeof(Degree))
           .Cast<Degree>()
           .Select((item, index) => new SelectListItem
                {
                    Text = item.ToString(),
                    Value = item.ToString(),
                    Selected = Model.Degree == item.ToString()
                }).ToList());
    //政治面貌的枚举生成SelectListItem,用于下拉列表框
    var statusSelectItemList = new List<SelectListItem>();
    statusSelectItemList.AddRange(
        Enum.GetValues(typeof(Status))
           .Cast<Status>()
           .Select((item, index) => new SelectListItem
           {
               Text = item.ToString(),
               Value = item.ToString(),
               Selected = Model.Status == item.ToString()
           }).ToList());
}
<div class="t-widget t-grid" style="width: 100%; height: 100%">
    @using (Html.BeginForm("Edit", "Biography", FormMethod.Post))
    {
        <div class="t-edit-form-container" style="width: 100%;">
            @Html.ValidationSummary(true)
            <fieldset style="width: 100%; border: 0px;">
                <legend style="font-size: 20px;">修改员工档案:</legend>
                <table width="100%">
                    @*工号、姓名、性别*@
                    <tr>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.ID)
                            </div>
                            <div class="editor-field">
                                @Html.Raw("<input id='ID' name='ID' disabled='disabled' type='text' value='" + Model.ID + "'/>")
                                @Html.ValidationMessageFor(model => model.ID)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Name)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.Name)
                                @Html.ValidationMessageFor(model => model.Name)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Sex)
                            </div>
                            <div class="editor-field">
                                @Html.DropDownListFor(model => model.Sex
                                   , new[]
                                         {
                                             new SelectListItem(){Text="男",Value="男",Selected = Model.Sex=="男"}, 
                                             new SelectListItem(){Text="女",Value="女",Selected = Model.Sex=="女"}, 
                                         })
                                @Html.ValidationMessageFor(model => model.Sex)
                            </div>
                        </td>
                    </tr>
                    @*部门、职位、学历（部门和职位是数据库中,学历为枚举）*@
                    <tr>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.DepartmentId)
                            </div>
                            <div class="editor-field">
                                <select id="DepartmentId" name="DepartmentId" data-val="true" data-val-required="请先添加部门">
                                </select>
                                @Html.ValidationMessageFor(model => model.DepartmentId)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.PostId)
                            </div>
                            <div class="editor-field">
                                <select id="PostId" name="PostId" data-val="true" data-val-required="请先添加职位">
                                </select>
                                @Html.ValidationMessageFor(model => model.PostId)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Degree)
                            </div>
                            <div class="editor-field">
                                @Html.DropDownListFor(model => model.Degree, degreeSelectItemList)
                                @Html.ValidationMessageFor(model => model.Degree)
                            </div>
                        </td>
                    </tr>
                    @*身份证号码、毕业学校、籍贯*@
                    <tr>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Identitycard)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.Identitycard)
                                @Html.ValidationMessageFor(model => model.Identitycard)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Gradution)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.Gradution)
                                @Html.ValidationMessageFor(model => model.Gradution)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.BirthPlace)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.BirthPlace)
                                @Html.ValidationMessageFor(model => model.BirthPlace)
                            </div>
                        </td>
                    </tr>
                    @*民族、政治面貌、现住址*@
                    <tr>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Nationality)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.Nationality)
                                @Html.ValidationMessageFor(model => model.Status)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Status)
                            </div>
                            <div class="editor-field">
                                @Html.DropDownListFor(model => model.Status, statusSelectItemList)
                                @Html.ValidationMessageFor(model => model.Status)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.PersentAddress)
                            </div>
                            <div class="editor-field">
                                @Html.TextAreaFor(model => model.PersentAddress)
                                @Html.ValidationMessageFor(model => model.PersentAddress)
                            </div>
                        </td>
                    </tr>
                    @*出生日期、户口地址、邮编*@
                    <tr>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Birthday)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.Birthday)
                                @Html.ValidationMessageFor(model => model.Birthday)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.HomeAddress)
                            </div>
                            <div class="editor-field">
                                @Html.TextAreaFor(model => model.HomeAddress)
                                @Html.ValidationMessageFor(model => model.HomeAddress)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Zip)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.Zip)
                                @Html.ValidationMessageFor(model => model.Zip)
                            </div>
                        </td>
                    </tr>
                    @*电话、入职时间、员工状态、试用天数*@
                    <tr>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.Telephone)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.Telephone)
                                @Html.ValidationMessageFor(model => model.Telephone)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.JoinTime)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.JoinTime)
                                @Html.ValidationMessageFor(model => model.JoinTime)
                            </div>
                        </td>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.EmployeeStatus)
                            </div>
                            <div class="editor-field">
                                @Html.DropDownListFor(model => model.EmployeeStatus
                                   , new[]
                                         { 
                                             new SelectListItem(){Text="正式状态",Value="正式状态",Selected = Model.EmployeeStatus=="正式状态"},
                                             new SelectListItem(){Text="试用状态",Value="试用状态",Selected = Model.EmployeeStatus=="试用状态"}
                                         })
                                @Html.ValidationMessageFor(model => model.EmployeeStatus)
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div class="editor-label">
                                @Html.LabelFor(model => model.ProbationDates)
                            </div>
                            <div class="editor-field">
                                @Html.EditorFor(model => model.ProbationDates)
                                @Html.ValidationMessageFor(model => model.ProbationDates)
                            </div>
                        </td>
                    </tr>
                </table>
            </fieldset>
        </div>
        <p>
            <input type="submit" value="保存" style="height: 23px; width: 10%;" />
            <input type="button" value="返回" id="BiographyIndex" style="height: 23px; width: 10%;" />
        </p>
    }
</div>
